package com.example.teacher;


import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.util.Log;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.student.CourseSelection;
import com.example.student.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class TeacherHome extends AppCompatActivity {
    private BottomNavigationView bottomNavigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_teacher_home);
        bottomNavigationView = findViewById(R.id.bottom_navigation_admin);
        bottomNavigationView.setOnItemSelectedListener(item -> {
            Fragment selectedFragment = null;
            int itemId = item.getItemId();
            if (itemId == R.id.navigation_home) {
                Bundle bundle = new Bundle();
                bundle.putInt("teacher_id", getIntent().getIntExtra("teacher_id", -1));
                HomeFragment homeFragment = new HomeFragment();
                homeFragment.setArguments(bundle);
                loadFragment(homeFragment);
                return true;
            } else if (itemId == R.id.navigation_courses) {
                Bundle bundle = new Bundle();
                bundle.putInt("teacher_id", getIntent().getIntExtra("teacher_id", -1));
                CoursesFragment coursesFragment = new CoursesFragment();
                coursesFragment.setArguments(bundle);
                loadFragment(coursesFragment);
                return true;
            } else if (itemId == R.id.navigation_profile) {
                Bundle bundle = new Bundle();
                bundle.putInt("teacher_id", getIntent().getIntExtra("teacher_id", -1));
                ProfileFragmentAdmin profileFragmentAdmin = new ProfileFragmentAdmin();
                profileFragmentAdmin.setArguments(bundle);
                loadFragment(profileFragmentAdmin);
                return true;
            }
            return false;
        });

        // 默认加载选课信息页面
        if (savedInstanceState == null) {
            bottomNavigationView.setSelectedItemId(R.id.navigation_home);
        }
    }
    private void loadFragment(Fragment fragment) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment_container, fragment);
        transaction.commit();
    }
}